package com.funo.logic.controller;

import cn.hutool.json.JSONUtil;
import com.funo.logic.model.LogicService;
import com.funo.logic.response.HandleResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("logicService")
public class LogicServiceController extends AbstractController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @PostMapping("saveOrUpdate")
    public HandleResult saveOrUpdate(@RequestBody LogicService logicService) {
        stringRedisTemplate.delete(getCacheKey(logicService.getId()));
        stringRedisTemplate.opsForValue().set(getCacheKey(logicService.getId()), JSONUtil.toJsonStr(logicService));
        return HandleResult.success();
    }

    @Override
    public String getCachePrefix() {
        return "logicService:";
    }
}
